package com.example.controller;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/process")
public class ProcessController {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    // 启动流程
    @PostMapping("/start")
    public String startProcess() {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");
        return "流程已启动，流程ID: " + processInstance.getId();
    }

    // 获取任务列表
    @GetMapping("/tasks")
    public List<Task> getTasks(@RequestParam String assignee) {
        return taskService.createTaskQuery().taskAssignee(assignee).list();
    }

    // 完成任务
    @PostMapping("/complete-task")
    public String completeTask(@RequestParam String taskId) {
        taskService.complete(taskId);
        return "任务已完成，任务ID: " + taskId;
    }
}